//
//  LGGongJiDetailViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/26.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGGongJiDetailViewController.h"

@interface LGGongJiDetailViewController ()
@property(nonatomic, strong) UIScrollView                     *scrollView;
@end

@implementation LGGongJiDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"张小华";
    [self st_setRightItemWithImage:[UIImage imageNamed:@"分享"]];
    [self configSubView];
    
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = [UIColor whiteColor];
    __weak typeof(self) weakSelf =  self;
    
    STLabel * IDLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 0, 200,44)
                                                  text:@"圆号:123123"
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustWitdhWithLabel:IDLable];
    [header addSubview:IDLable];
    
    STLabel * nameLable = [[STLabel alloc] initWithFrame:CGRectMake(IDLable.right + 20, 0, 200,44)
                                                  text:@"建陵人:唠叨打"
                                             textColor:FirstTextColor
                                                  font:15
                                           isSizetoFit:NO
                                         textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustWitdhWithLabel:nameLable];
    [header addSubview:nameLable];
    
    STButton * frinedButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)
                                                     title:@"加好友"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:14
                                              cornerRadius:4
                                           backgroundColor:TM_redColor
                                           backgroundImage:nil
                                                     image:nil];
    [frinedButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedAddFriendButton];
    }];
    frinedButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    frinedButton.right = UIScreenWidth - 15;
    frinedButton.centerY = 22;
    [header addSubview:frinedButton];
    
    NSArray * array = @[@"浏览:1.0w",@"祭拜:1.0w",@"亲情:1.0w",@"修缮:1.0w",@"财富:1.0w"];
    CGFloat lableWith = UIScreenWidth/array.count;
    for (NSInteger i = 0; i < array.count; i ++) {
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 44, lableWith, 20)
                                                         text:array[i]
                                                    textColor:SecendTextColor
                                                         font:13
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        [header addSubview:titleLable];
        titleLable.left = i * lableWith;
    }
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 100, 105)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"1"]];
    iconButton.centerX = UIScreenWidth / 2;
    iconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    iconButton.top = 70;
    [header addSubview:iconButton];
    
    
    STLabel * diedLable = [[STLabel alloc] initWithFrame:CGRectMake(0, iconButton.bottom, UIScreenWidth, 44)
                                                     text:@"涨毛毛(2018年03月26~2018年03月26日)"
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [header addSubview:diedLable];
    
    
    STButton * attentionButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)
                                                        title:@"关注"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:14
                                                 cornerRadius:4
                                              backgroundColor:FlatGray
                                              backgroundImage:nil
                                                        image:nil];
    [attentionButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedAttentionButton];
    }];
    attentionButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    attentionButton.centerX = UIScreenWidth/2;
    attentionButton.top = diedLable .bottom  +5;
    [header addSubview:attentionButton];
    
    
    STButton * baijiButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)
                                                           title:@"前往祭拜"
                                                      titleColor:[UIColor whiteColor]
                                                       titleFont:14
                                                    cornerRadius:4
                                                 backgroundColor:FlatGray
                                                 backgroundImage:nil
                                                           image:nil];
    [baijiButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedBaiJiButton];
    }];
    baijiButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    baijiButton.centerX = UIScreenWidth/2;
    baijiButton.top = attentionButton .bottom  +20;
    [header addSubview:baijiButton];
    
    //scrollview
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(60, baijiButton.bottom + 30, UIScreenWidth - 120, 90)];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [header addSubview:self.scrollView];
    NSArray * imageArray = @[@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1"];
    for (NSInteger i = 0; i < imageArray.count; i ++) {
        STButton * imageButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 70, 90)
                                                         title:nil
                                                    titleColor:nil
                                                     titleFont:0
                                                  cornerRadius:0
                                               backgroundColor:nil
                                               backgroundImage:[UIImage imageNamed:imageArray[i]]
                                                         image:nil];
        [self.scrollView addSubview:imageButton];
        imageButton.left = i * 70 + 10 * i;
        self.scrollView.contentSize = CGSizeMake(imageButton.right, 0);
    }
    
    STButton * lastButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"左"]];
    lastButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    lastButton.left = 15;
    [lastButton setClicAction:^(UIButton *sender) {
        CGFloat toOffset = weakSelf.scrollView.contentOffset.x - weakSelf.scrollView.width;
        if (toOffset<0) {
            toOffset = 0;
        }
        [weakSelf.scrollView setContentOffset:CGPointMake(toOffset, 0) animated:YES];
    }];
    lastButton.centerY = self.scrollView.centerY;
    [header addSubview:lastButton];
    
    STButton * nextButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:@"右"]];
    nextButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    nextButton.right = UIScreenWidth - 15;
    nextButton.centerY = self.scrollView.centerY;
    [nextButton setClicAction:^(UIButton *sender) {
        CGFloat toOffset = weakSelf.scrollView.contentOffset.x + weakSelf.scrollView.width;
        if (toOffset> (weakSelf.scrollView.contentSize.width - weakSelf.scrollView.width)) {
            toOffset = (weakSelf.scrollView.contentSize.width - weakSelf.scrollView.width);
        }
        [weakSelf.scrollView setContentOffset:CGPointMake(toOffset, 0) animated:YES];
    }];
    [header addSubview:nextButton];
    
    STLabel * desTitleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, self.scrollView.bottom + 20, UIScreenWidth, 44)
                                                     text:@"生平简介"
                                                textColor:FirstTextColor
                                                     font:18
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:desTitleLable];
    
    NSString * des = @"毛泽东(1893年12月26日-1976年9月9日)，字润之(原作咏芝，后改润芝)，笔名子任。湖南湘潭人。中国人民的领袖，马克思主义者，伟大的无产阶级革命家、战略家和理论家，中国共产党、中国人民解放军和中华人民共和国的主要缔造者和领导人诗人，书法家。[1] 1949至1976年，毛泽东担任中华人民共和国最高领导人。他对马克思列宁主义的发展、军事理论的贡献以及对共产党的理论贡献被称为毛泽东思想。因毛泽东担任过的主要职务几乎全部称为主席，所以也被人们尊称为“毛主席”。毛东被视为现代世界历史中最重要的人物之一，《时代》杂志也他评为20世纪最具影响100人之一";
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(15, desTitleLable.bottom + 10, UIScreenWidth - 30, 44)
                                                        text:des
                                                   textColor:SecendTextColor
                                                        font:14
                                                 isSizetoFit:NO
                                               textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustheightWithLabel:desLable];
    [header addSubview:desLable];
    
    header.height = desLable.bottom + 10;
    self.tableView.tableHeaderView = header;
}




#pragma mark --Action Method
- (void)st_rightBarAction:(id)sender{
    LGShareViewController * vc = [LGShareViewController new];
    [vc setOnSelctedShareHandle:^(NSString *shareName) {
        NSLog(@"%@",shareName);
    }];
    [self presentViewController:vc animated:NO completion:nil];
}
- (void)onSelctedAddFriendButton{
    
}
- (void)onSelctedAttentionButton{
    
}
- (void)onSelctedBaiJiButton{
    
}
@end
